package com.qf.fmw.service.impl;

import com.qf.fmw.dao.AddressDao;
import com.qf.fmw.dao.impl.AddressDaoImpl;
import com.qf.fmw.entity.bo.AddressBo;
import com.qf.fmw.entity.bo.OrderBo;
import com.qf.fmw.entity.vo.RespResult;
import com.qf.fmw.service.AddressService;

import java.util.List;

public class AddressServiceImpl implements AddressService {
    private AddressDao addressDao = new AddressDaoImpl();

    @Override
    public RespResult showAllAddresses() {
        List<AddressBo> addressList = addressDao.selectAllAddresses();
        if (addressList == null || addressList.isEmpty()) {
            return RespResult.respError("未找到地址", null);
        }
        return RespResult.respSuccess("找到地址", addressList);
    }

    @Override
    public RespResult searchAddress(String query) {
        List<AddressBo> addressList = addressDao.searchAddress(query);
        if (addressList == null || addressList.isEmpty()) {
            return RespResult.respError("未找到符合条件的地址", null);
        }
        return RespResult.respSuccess("找到符合条件的地址", addressList);
    }

    @Override
    public RespResult deleteAddress(int addressId) {
        Integer deleted = addressDao.deleteAddress(addressId);
        if (deleted == 0) {
            return RespResult.respError("删除失败", null);
        }
        return RespResult.respSuccess("删除成功", null);
    }

    @Override
    public RespResult addAddress(String name, String phone, String detail, int state) {
        boolean added = addressDao.addAddress(name, phone, detail, state);
        if (added) {
            return RespResult.respSuccess("地址添加成功", null);
        } else {
            return RespResult.respError("地址添加失败", null);
        }
    }

    @Override
    public RespResult updateAddress(int addressId, String name, String phone, String detail, int state) {
        boolean updated = addressDao.updateAddress(addressId, name, phone, detail, state);
        if (updated) {
            return RespResult.respSuccess("地址更新成功", null);
        } else {
            return RespResult.respError("地址更新失败", null);
        }
    }




}
